<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title>合同记录</title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div style="width: 100%; height: 98%;">
		<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
			<legend><span>查询条件</span></legend>
			<div id="queryForm" class="fieldset-body">
				<table class="form-table" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="form-label">
							<span>合同编号：</span>
							<input name="contractNo" class="mini-textbox" style="width: 150px">
							<input name="contractNo_link" class="mini-hidden" value="like">
							<span>签订日期从：</span>
							<input name="signTime_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
							<span>到：</span>
							<input name="signTime_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
							<span>截止日期从：</span>
							<input name="outTime_from" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
							<span>到：</span>
							<input name="outTime_to" class="mini-datepicker" format="yyyy-MM-dd" style="width: 150px" />
							<a style="margin: 0 0 0 0;" class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
							<a class="mini-menubutton " menu="#popupMenu">编辑</a>
							<ul id="popupMenu" class="mini-menu" style="display:none;">
								<li onclick="doEdit('add')">新增</li>
								<li onclick="doEdit('update')">修改</li>
								<li onclick="doDelete()">删除</li>
							</ul>
						</td>
					</tr>
				</table>
			</div>
		</fieldset>

		<div class="mini-fit">
			<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" idField="instID" allowResize="true"
				multiSelect="true">
				<div property="columns">
					<div type="indexcolumn" width="20"></div>
					<div field="userName" headerAlign="center" width="80">员工姓名</div>
					<div field="contractNo" headerAlign="center" width="80">合同编号</div>
					<div field="contractName" headerAlign="center" width="80">合同名称</div>
					<div field="signTime" dateFormat="yyyy-MM-dd" headerAlign="center" width="80" allowSort="true">签订日期
					</div>
					<div field="outTime" dateFormat="yyyy-MM-dd" headerAlign="center" width="80" allowSort="true">有效截止日期
					</div>
				</div>
			</div>
		</div>
	</div>

	<div id="detailWin" class="mini-window" style="width:500px;height:320px;" showMaxButton="true" showCollapseButton="true"
		showShadow="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
		<div id="detailForm">
			<input name="dormitoryID" class="mini-hidden">
			<table align="center" style="border-collapse:separate; border-spacing:0px 4px;">
				<tr>
					<td align="right">员工姓名：</td>
					<td align="left">
						<input id="userName" name="userName" class="mini-textbox" enabled="false" style="width: 60%" />
						<input id="userID" name="userID" class="mini-hidden" />
						<a class="mini-button" iconCls="icon-edit" plain="true"
							onclick="miniui.openDialog('/page/system/win_user_select.html','userName,userID')">修改</a>
					</td>
				</tr>
				<tr>
					<td align="right">合同编号：</td>
					<td align="left"><input name="contractNo" class="mini-textbox" width="240"></td>
				</tr>
				<tr>
					<td align="right">合同名称：</td>
					<td align="left"><input name="contractName" class="mini-textbox" width="240"></td>
				</tr>
				<tr>
					<td align="right">签订日期：</td>
					<td align="left"><input name="signTime" class="mini-datepicker" format="yyyy-MM-dd"></td>
				</tr>
				<tr>
					<td align="right">截止日期：</td>
					<td align="left"><input name="outDate" class="mini-datepicker" format="yyyy-MM-dd"></td>
				</tr>
				<tr>
					<td align="right">说明：</td>
					<td align="left"><input name="description" class="mini-textbox" width="360"></td>
				</tr>
			</table>
		</div>
		<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
			<a class="mini-button" iconCls="icon-save" id="saveButton" onClick="saveAction('保存')">保存</a>
			<a class="mini-button" iconCls="icon-cancel" onClick="cancel()">取消</a>
		</div>
	</div>

</body>

<script type="text/javascript">
	miniInit();

	var queryForm = new mini.Form("#queryForm");
	var datagrid = miniui.getControl("datagrid"); // 表定义列表
	datagrid.set({
		url: http.getUrl("/com/map/page.do")
	});

	var detailForm = new mini.Form("#detailForm");
	var detailWin = mini.get("detailWin");

	/*********************************************************
	 * 操作方法
	 *********************************************************/
	function search() {
		var data = queryForm.getData(true, false);
		data.tableName = "REC_CONTRACT_VIEW";
		datagrid.load(data);
	}

	function doEdit(type) {
		debugger
		if (type == 'add') {
			detailWin.setTitle("新增");
			detailForm.reset();
			var data = {
				"status": 1
			};
			detailForm.setData(data);
		} else {
			if (datagrid.getSelected() == undefined) {
				mini.alert("请先选择要编辑的数据!", "提示", null);
				return;
			}
			detailWin.setTitle("修改");
			detailForm.setData(datagrid.getSelected());
		}
		detailWin.showAtPos('center', 'middle');
	}

	function saveAction(type) {
		miniui.mask("数据保存中...");
		var data = detailForm.getData(true, false);
		if (data.recordID) {
			data.recordID_ = data.recordID;
			data.recordID = null;
		}
		data.tableName = "REC_CONTRACT";
		// debugger
		http.post("/com/map/save.do", data, function (page) {
			mini.unmask();
			detailWin.hide();
			if (page.success) {
				miniui.showSuccessTip("保存成功");
				search();
			} else {
				miniui.showErrorMessageBox(page.message);
			}
		});
	}

	function cancel() {
		detailWin.hide();
	}

	function doDelete() {
		if (datagrid.getSelected()) {
			mini.confirm("确定要删除选中的记录吗？", "确定？",
				function (action) {
					if (action == "ok") {
						var row = datagrid.getSelected();
						var data = {
							"recordID": row.recordID
						};
						data.tableName = "REC_CONTRACT";
						http.post("/com/map/delete.do", data, function (page) {
							if (page.success) {
								miniui.showSuccessTip("删除成功");
								datagrid.removeRow(row);
							} else {
								miniui.showErrorMessageBox(page.message);
							}
						});
					}
				});
		} else {
			miniui.showErrorMessageBox("请先选择要删除的记录！");
		}
	}

</script>

</html>